const birdDom = document.querySelector('.bird');
const birdStyle = getComputedStyle(birdDom);
const birdWidth = parseFloat(birdStyle.width);
const birdHeight = parseFloat(birdStyle.height);
const birdTop = parseFloat(birdStyle.top);
const birdLeft = parseFloat(birdStyle.left);
const gameDom = document.querySelector('.game');
const gameHeight = gameDom.clientHeight;




class Bird extends Rectangle {
    constructor() {
        super(birdWidth, birdHeight, birdTop, birdLeft, 0, 0, birdDom);
        //特有的属性
        this.g = 1200  //向下的加速度
        this.maxY = gameHeight - landHeight - this.height;
        this.swingAction = 1;
        this.timer = null;
        this.render();
    }
    render() {
        super.render();
        this.dom.className = `bird swing${this.swingAction}`;
    }
    move(duration) {
        super.move(duration);
        this.ySpeed += this.g * duration;

    }
    //向上跳
    jump() {
        this.ySpeed = -350;
    }
    onMove() {
        if (this.top < 0) {
            this.top = 0;
        } else if (this.top > this.maxY) {
            this.top = this.maxY;
        }

    }
    //挥动翅膀
    flying() {
        if (this.timer) {
            return;
        }
        this.timer = setInterval(() => {
            this.swingAction = (this.swingAction + 1) % 3 + 1;
            this.render();
        }, 300)
    }
    //停止挥动翅膀
    stopFlying() {
        clearInterval(this.timer);
        this.timer = null;
    }
}